# %%
import os

# os.environ['OPENAI_API_KEY'] = ''
# %% use env
from dotenv import load_dotenv

load_dotenv()
# %%
from langchain_community.llms import OpenAI

llm = OpenAI(model_name="gpt-3.5-turbo-instruct")

# %%
our_prompt = """
I love trips,and I have been to 6 countries.
I plan to visit few more soon.

Can you create a post for tweet in 10 words for the above?
"""  # 10 words -> 这个10 我们希望能动态指定

print(our_prompt)
# %%
res = llm(our_prompt)
print(res)

# %% Prompt Template
from langchain_community.llms import OpenAI
from langchain import PromptTemplate

llm = OpenAI(model_name="gpt-3.5-turbo-instruct")

# %% Using F-String
'''
F-String is a Python feature that allows easy string formatting by placing variables inside curly braces within a string,making code more readable and efficient.
__Code:__
name = "Alice"
age = 25
message f"My name is {name} and I am {age} years old."
print(message)

__Output:__
My name is Allce and I am 25 years old.
'''

wordsCount = 5
our_txt = "I love trips,and I have been to 6 countries. I plan to visit few more soon."
our_prompt = f"""
{our_txt}

Can you create a post for tweet in {wordsCount} words for the above?
"""
print(our_prompt)

# %%
print(llm(our_prompt))

# %% Using Prompt Template
# Prompt templates helps us in keeping our code neat and clean when we are bullding more complex

template = """
{our_txt}

Can you create a post for tweet in {wordsCount} words for the above?
"""

# %%
prompt = PromptTemplate(
    input_variables=['wordsCount', 'our_txt'],
    template=template
)

final_prompt = prompt.format(
    wordsCount='3',
    our_txt=our_txt
)

print(final_prompt)
print(llm(final_prompt))
